/**
 * Created by alice on 2017/5/04 0001
 */
;-function (window) {
    "use strict";
    //TODO 预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        layer: null,
        city: null,
        judge_uid: null,
        secretary: null,
        start: null,
        end: null,
        current_court_uid: null,
        case_type: null,
        _user_court_uid: null,
        page_size: 12,
        judge_secretary_list: null,
        page_index: 1
    };
    //TODO 初始化的方法写这里面
    var init = function () {
        init_ready();//加载预设变量
        init_event();

        function init_event() {//TODO 初始化页面事件
            var current_day = utils.get_url_param(0);
            //查询的开始时间默认给今天
            $('#startTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                // console.log(ev.date.valueOf());
            });
            var end_time = $('#endTime');
            $('#endTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                // console.log(ev.date.valueOf());
            });

            if (null != ready.start && "" != ready.start) {
                $("#startTime").find("input").val(ready.start);
            } else {
                var temp = new Date();
                var defaultStartTime = temp.getFullYear() + "-01-01";
                $("#startTime").find("input").val(defaultStartTime);
            }
            if (null != ready.end) {
                end_time.find("input").val(ready.end);
            } else {
                end_time.find("input").val(current_day);
            }

            $("#selectAllChildCourts").change(function () {
                Class.all_child_option_change();
            });
            $(".container-fluid").show();

            //点击查询按钮
            $("#conditionBtn").click(function () {
                $("#loading").show();
                Class.get_sum_case();
            });
            if (ready.judge_uid) {
                $.get(r.base_path + "user/getUserByUid", {uid: ready.judge_uid}, function (result) {
                    if (result) {
                        if (!result.data) {
                            layui.use('layer', function () {
                                layui.layer.msg("未能找到指定法官，将为您加载所有的庭审数据");
                            });

                        }
                        ready._user_court_uid = result.data.courtUid;
                        Class.init(ready._user_court_uid);
                    }
                }, 'json')
            } else if (ready.secretary) {
                $.get(r.base_path + "user/getUserByUid", {uid: ready.secretary}, function (result) {
                    if (result) {
                        if (!result.data) {
                            layui.use('layer', function () {
                                layui.layer.msg("未能找到指定书记员，将为您加载所有的庭审数据");
                            });
                        }
                        ready._user_court_uid = result.data.courtUid;
                        Class.init(ready._user_court_uid);
                    }
                }, 'json')
            } else {
                if (ready.current_court_uid) {
                    Class.init(ready.current_court_uid);
                } else {
                    Class.init();
                }
            }
        }

        function init_ready() {//TODO 初始化预设值
            layui.use('layer', function () {
                ready.layer = layui.layer;
            });
            ready.city = utils.get_url_param("city") || r.court_uid;
            ready.judge_uid = utils.get_url_param("judge");
            ready.secretary = utils.get_url_param("secretary");
            ready.start = utils.get_url_param("start");
            ready.end = utils.get_url_param("end");
            ready.current_court_uid = utils.get_url_param("currentCourtUid");
            ready.case_type = utils.get_url_param("caseType");
        }
    };
    //TODO 内部调用的方法写这里
    var Class = {
        init: function (_court_uid) {
            ready.city = _court_uid ? _court_uid : r.court_uid;
            !_court_uid ? ready._user_court_uid = null : "";
            Class.select_all_child_courts();
            Class.select_all_court_room();
            Class.select_all_case_type();
            Class.select_judge();
            Class.select_secretary();
            Class.get_sum_case();
        },
        get_sum_case: function () {
            if (r.flag_search) {
                Class.all_count_case_review();
            } else {
                Class.count_case_review();
            }
        },
        all_child_option_change: function () {
            var _current_court_uid = $("#selectAllChildCourts").val();
            Class.select_all_court_room(_current_court_uid);
            Class.select_all_case_type(_current_court_uid);
            Class.select_judge(_current_court_uid);
            Class.select_secretary(_current_court_uid);
            // Class.get_sum_case();
        },
        select_all_child_courts: function () {
            // console.info(ready.city, r.court_uid);
            var select_child_courts = $("#selectAllChildCourts");
            select_child_courts.empty();
            $.each(r.court_list, function (i, n) {
                select_child_courts.append("<option value='" + n.uid + "'>" + n.name + "</option>");
            });
            select_child_courts.val(ready.city);
        },
        select_all_court_room: function (current_court_id) {
            if (current_court_id) {
                ready.city = current_court_id;
            }
            // console.log(ready.city);
            var court_room = $("#allCourtRooms").empty();
            court_room.append("<option value=''>" + "所有法庭" + "</option>");
            $.each(courtroomList, function (i, valueOfElement) {
                if (valueOfElement.courtUid == ready.city && valueOfElement.active == 1) {
                    court_room.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                }
            });
        },
        select_all_case_type: function (current_court_id) {
            if (current_court_id) {
                ready.city = current_court_id;
            }
            var case_type = $("#caseTypeName").empty();
            if (null != ready.case_type && '' != ready.case_type && 'null' != ready.case_type) {
                $.each(caseTypeList, function (i, valueOfElement) {
                    if (ready.case_type == valueOfElement.uid) {
                        case_type.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                    }
                });
            } else {
                case_type.append("<option value=''>" + "所有类型" + "</option>");
                $.each(caseTypeList, function (i, valueOfElement) {
                    case_type.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                });
            }
        },
        select_judge: function (current_court_id) {
            $.ajaxSetup({
                async: false
            });
            if (current_court_id) {
                ready.city = current_court_id;
            }
            !ready._user_court_uid ? ready.judge_uid = null : "";

            $.get(r.base_path + "caseCount/getJudgeAndSecretary", {
                courtUid: ready.city
            }, function (result) {
                if (result.data) {
                    ready.judge_secretary_list = result.data;
                    // console.log(result);
                    var select_judge = $("#allJudges").empty();
                    if (ready.judge_uid) {
                        $.each(result.data.judgeList, function (i, valueOfElement) {
                            if (valueOfElement.uid == ready.judge_uid) {
                                select_judge.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                                $(".active").find("span").append("&nbsp;" + valueOfElement.name + "审理过的案件");//今日开庭和排期
                            }
                        });

                    } else {
                        select_judge.append("<option value=''>" + "所有法官" + "</option>");
                        $.each(result.data.judgeList, function (i, valueOfElement) {
                            select_judge.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                        });
                    }
                }
            }, 'json');
            $.ajaxSetup({
                async: true
            });
        },
        select_secretary: function (current_court_id) {
            if (current_court_id) {
                ready.city = current_court_id;
            }
            !ready._user_court_uid ? ready.secretary = null : "";
            if (ready.judge_secretary_list) {
                //console.log(result);
                var select_secretary = $("#allSecretary").empty();
                if (ready.secretary) {
                    $.each(ready.judge_secretary_list.secretaryList, function (i, valueOfElement) {
                        if (valueOfElement.uid == ready.secretary) {
                            select_secretary.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                            select_secretary.find("input").val(valueOfElement.uid);
                            $(".active").find("span").append("&nbsp;" + valueOfElement.name + "审理过的案件");//今日开庭和排期
                        }
                    });

                } else {
                    select_secretary.append("<option value=''>" + "所有书记员" + "</option>");
                    $.each(ready.judge_secretary_list.secretaryList, function (i, valueOfElement) {
                        select_secretary.append("<option value='" + valueOfElement.uid + "'>" + valueOfElement.name + "</option>");
                    });
                }
            }
        },
        count_case_review: function (page) {
            Class.page(1, 1, null);
            $('#loading').show();
            page = ready.page_index = page||1;
            //条件
            var caseno = $("#caseno").val();
            var caseName = $("#caseName").val();
            var caseTypeName = $("#caseTypeName").val();
            var courtRoom = $("#allCourtRooms").val();
            var judge = $("#allJudges").val();
            var secretary = $("#allSecretary").val();
            var startTime = $("#startTime").find("input").val();
            var endTime = $("#endTime").find("input").val();
            if (secretary == 'null') {
                secretary = null;
            }
            if (judge == 'null') {
                judge = null;
            }
            $.post(r.base_path + "review/countReviewOrPlan", {
                archives: caseno,
                caseName: caseName,
                type: caseTypeName,
                courtRoom: courtRoom,
                judgeId: judge,
                secretaryId: secretary,
                startDate: startTime,
                endDate: endTime,
                courtUid: ready.city,
                status: 0,
                review: 1,
                page: page,
                pageSize: ready.page_size
            }, function (result) {
                $('#loading').hide();
                if (result && result.code == 0) {
                    Class.page(page, Math.ceil(result.data / 12), Class.case_review);
                } else {

                }
            }, 'json').fail(function () {
                $('#loading').hide();
            });
            Class.case_review(page);
        },
        case_review:function (page) {
            page = ready.page_index = page||1;
            //条件
            var caseno = $("#caseno").val();
            var caseName = $("#caseName").val();
            var caseTypeName = $("#caseTypeName").val();
            var courtRoom = $("#allCourtRooms").val();
            var judge = $("#allJudges").val();
            var secretary = $("#allSecretary").val();
            var startTime = $("#startTime").find("input").val();
            var endTime = $("#endTime").find("input").val();
            var row_no_padding = $(".row-no-padding").empty();
            if (secretary == 'null') {
                secretary = null;
            }
            if (judge == 'null') {
                judge = null;
            }
            $.ajax({
                url: r.base_path + "review/getReviewOrPlan",
                type: "post",
                dataType: "json",
                data: {
                    archives: caseno,
                    caseName: caseName,
                    type: caseTypeName,
                    courtRoom: courtRoom,
                    judgeId: judge,
                    secretaryId: secretary,
                    startDate: startTime,
                    endDate: endTime,
                    courtUid: ready.city,
                    status: 0,
                    review: 1,
                    page: page,
                    pageSize: ready.page_size
                },
                success: function (result) {
                    $('#loading').hide();
                    if (result.code == 0) {
                        if (result.data.count <= 0) {
                            row_no_padding.append('<span>暂无开庭信息</span>');
                        } else {
                            var picNum = 6;
                            $.each(result.data.data, function (i, valueOfElement) {
                                var caseName = valueOfElement.name;
                                var startDate = valueOfElement.startDate;
                                var uid = valueOfElement.planUid;
                                var status = valueOfElement.status;
                                var courtroom_name = valueOfElement.courtroomName;
                                var statusName = "";
                                if (0 == status) {
                                    statusName = "排期";
                                } else if (1 == status || 5 == status) {
                                    statusName = "开庭";
                                } else if (2 == status) {
                                    statusName = "休庭";
                                } else if (3 == status) {
                                    statusName = "闭庭";
                                } else {
                                    statusName = "归档";
                                }
                                var success = false;
                                if (favorites && $.inArray(uid, favorites) > -1) {
                                    success = true;
                                }
                                var randomNum = parseInt(picNum * Math.random() + 1);//随机出1到picNum的整数
                                var href = r.base_path + "system_monitor/panel_play?planUid=" + uid + "&vlcCourtUid=" + valueOfElement.courtUid + '&courtUid=' + r.court_uid;
                                var html = '<div class="col-md-2 col-xs-6">' +
                                    '<div class="more-reviewing-item">' +
                                    '<a href="' + href + '">' +
                                    '<div class="more-reviewing-item-img-panel">' +
                                    '<p class="more-reviewing-item-img-panel-top">' + (courtroom_name ? courtroom_name : '未知') + '</p>' +
                                    '<img src="' + r.base_path + "assets/img/more_court_test" + randomNum + ".jpg" + '" alt="法院">' +
                                    '<p class="more-reviewing-item-img-panel-bottom">' + statusName + '</p>' +
                                    '</div>' +
                                    '<p id="startDate">' + startDate + '</p>' +
                                    '<p id="caseNoDis">' + (valueOfElement.archives ? valueOfElement.archives : '未知') + '</p>' +
                                    '<p class="more-reviewing-item-depiction">' +
                                    '<i class="fa fa-thumb-tack ' + ( success ? 'status-top' : '') + '" title="收藏" id="' + uid + '..' + valueOfElement.courtUid + '"></i>' +
                                    '<span>' + (caseName || "&nbsp;") + '</span>' +
                                    '</p>' +
                                    '</a>' +
                                    '</div>' +
                                    '</div>';
                                row_no_padding.append(html);
                            });
                            $(".fa-thumb-tack").click(function (e) {
                                e.preventDefault();
                                var cid = this.id.split('..');
                                var uid = cid[0];
                                var class_name = '' + this.className;
                                layui.use(['layer', 'form'], function () {
                                    var layer = layui.layer;
                                    if (class_name.indexOf("status-top") < 0) {
                                        layer.confirm('确定收藏吗？', {
                                            btn: ['是的', '取消'] //按钮
                                        }, function () {
                                            $.post(r.base_path + "favorite/like", {
                                                planUid: uid
                                            }, function (result) {
                                                favorites.push(uid);
                                                layer.msg(result.message);
                                                Class.case_review(ready.page_index);
                                            }, 'json')
                                        }, function () {

                                        });
                                    } else {
                                        layer.confirm('确定取消收藏吗？', {
                                            btn: ['是的', '取消'] //按钮
                                        }, function () {
                                            $.post(r.base_path + "favorite/unlike", {
                                                planUid: uid
                                            }, function (result) {
                                                var index = favorites.indexOf(uid);
                                                if (index > -1) {
                                                    favorites.splice(index, 1);
                                                }
                                                layer.msg(result.message);
                                                Class.case_review(ready.page_index);
                                            }, 'json')
                                        }, function () {

                                        });
                                    }
                                });
                            });
                        }
                    }
                    row_no_padding.show();
                },
                error: function () {
                    $("#loading").hide();
                    layui.use('layer', function () {
                        layui.layer.msg("载入数据发生了问题");
                    });
                }
            });
        },
        all_count_case_review: function (page) {
            Class.page(1, 1, null);
            $('#loading').show();
            page = ready.page_index = page||1;
            //条件
            var caseno = $("#caseno").val();
            var caseName = $("#caseName").val();
            var caseTypeName = $("#caseTypeName").val();
            var courtRoom = $("#allCourtRooms").val();
            var judge = $("#allJudges").val();
            var secretary = $("#allSecretary").val();
            var startTime = $("#startTime").find("input").val();
            var endTime = $("#endTime").find("input").val();
            if (secretary == 'null') {
                secretary = null;
            }
            if (judge == 'null') {
                judge = null;
            }

            $.post(r.base_path + "review/countReviewOrPlan", {
                archives: caseno,
                caseName: caseName,
                type: caseTypeName,
                courtRoom: courtRoom,
                judgeId: judge,
                secretaryId: secretary,
                startDate: startTime,
                endDate: endTime,
                courtUid: ready.city,
                status: 1,
                review: 1,
                page: page,
                pageSize: ready.page_size
            }, function (result) {
                if (result && result.code == 0) {
                    if (result.data <= 0) {
                        $('#loading').hide();
                    } else {
                        console.log('查询结果大于0');
                        Class.page(page, Math.ceil(result.data / 12), Class.all_case_review);
                    }
                } else {

                }
            }, 'json').fail(function () {
                $('#loading').hide();
            });
            Class.all_case_review(page);
        },
        all_case_review:function (page) {
            $('#loading').show();
            page = ready.page_index = page||1;
            //条件
            var caseno = $("#caseno").val();
            var caseName = $("#caseName").val();
            var caseTypeName = $("#caseTypeName").val();
            var courtRoom = $("#allCourtRooms").val();
            var judge = $("#allJudges").val();
            var secretary = $("#allSecretary").val();
            var startTime = $("#startTime").find("input").val();
            var endTime = $("#endTime").find("input").val();
            var row_no_padding = $(".row-no-padding").empty();
            if (secretary == 'null') {
                secretary = null;
            }
            if (judge == 'null') {
                judge = null;
            }
            $.ajax({
                url: r.base_path + "review/getReviewOrPlan",
                type: "post",
                dataType: "json",
                data: {
                    archives: caseno,
                    caseName: caseName,
                    type: caseTypeName,
                    courtRoom: courtRoom,
                    judgeId: judge,
                    secretaryId: secretary,
                    startDate: startTime,
                    endDate: endTime,
                    courtUid: ready.city,
                    status: 1,
                    review: 1,
                    page: page,
                    pageSize: ready.page_size
                },
                success: function (result) {
                    $('#loading').hide();
                    if (result.code == 0) {
                        if (result.data.count <= 0) {
                            row_no_padding.append('<span>暂无开庭信息</span>');
                        } else {
                            var picNum = 6;
                            $.each(result.data.data, function (i, valueOfElement) {
                                var caseName = valueOfElement.name;
                                var startDate = valueOfElement.startDate;
                                var uid = valueOfElement.planUid;
                                var status = valueOfElement.status;
                                var courtroom_name = valueOfElement.courtroomName;
                                var statusName = "";
                                if (0 == status) {
                                    statusName = "排期";
                                } else if (1 == status || 5 == status) {
                                    statusName = "开庭";
                                } else if (2 == status) {
                                    statusName = "休庭";
                                } else if (3 == status) {
                                    statusName = "闭庭";
                                } else {
                                    statusName = "归档";
                                }
                                var success = false;
                                if (favorites && $.inArray(uid, favorites) > -1) {
                                    success = true;
                                }
                                var randomNum = parseInt(picNum * Math.random() + 1);//随机出1到picNum的整数
                                var href = r.base_path + "system_monitor/panel_play?planUid=" + uid + '&courtUid=' + r.court_uid;
                                var html = '<div class="col-md-2 col-xs-6">' +
                                    '<div class="more-reviewing-item">' +
                                    '<a href="' + href + '">' +
                                    '<div class="more-reviewing-item-img-panel">' +
                                    '<p class="more-reviewing-item-img-panel-top">' + (courtroom_name ? courtroom_name : '未知') + '</p>' +
                                    '<img src="' + r.base_path + "assets/img/more_court_test" + randomNum + ".jpg" + '" alt="法院">' +
                                    '<p class="more-reviewing-item-img-panel-bottom">' + statusName + '</p>' +
                                    '</div>' +
                                    '<p id="startDate">' + startDate + '</p>' +
                                    '<p id="caseNoDis">' + (valueOfElement.archives ? valueOfElement.archives : '未知') + '</p>' +
                                    '<p class="more-reviewing-item-depiction">' +
                                    '<i class="fa fa-thumb-tack ' + (success ? 'status-top' : '') + '" title="收藏" id="' + uid + '..' + valueOfElement.courtId + '"></i>' +
                                    '<span>' + (caseName ? caseName : "&nbsp;") + '</span>' +
                                    '</p>' +
                                    '</a>' +
                                    '</div>' +
                                    '</div>';
                                row_no_padding.append(html);
                            });
                            $(".fa-thumb-tack").click(function (e) {
                                e.preventDefault();
                                var cid = this.id.split('..');
                                var uid = cid[0];
                                var class_name = '' + this.className;
                                layui.use(['layer', 'form'], function () {
                                    var layer = layui.layer;
                                    if (class_name.indexOf("status-top") < 0) {
                                        layer.confirm('确定收藏吗？', {
                                            btn: ['是的', '取消'] //按钮
                                        }, function () {
                                            $.post(r.base_path + "favorite/like", {
                                                planUid: uid
                                            }, function (result) {
                                                favorites.push(uid);
                                                layer.msg(result.message);
                                                Class.all_case_review(ready.page_index);
                                            }, 'json')
                                        }, function () {

                                        });
                                    } else {
                                        layer.confirm('确定取消收藏吗？', {
                                            btn: ['是的', '取消'] //按钮
                                        }, function () {
                                            $.post(r.base_path + "favorite/unlike", {
                                                planUid: uid
                                            }, function (result) {
                                                var index = favorites.indexOf(uid);
                                                if (index > -1) {
                                                    favorites.splice(index, 1);
                                                }
                                                layer.msg(result.message);
                                                Class.all_case_review(ready.page_index);
                                            }, 'json')
                                        }, function () {

                                        });
                                    }
                                });
                            });
                        }
                    }
                    row_no_padding.show();
                },
                error: function () {
                    $("#loading").hide();
                    layui.use('layer', function () {
                        layui.layer.msg("载入数据发生了问题");
                    });
                }
            });
        },
        page: function (now, totalPages, callback) {
            base.pagination('#_page', {
                currentPage: now,
                totalPages: totalPages||1,
                onPageClicked: function (page) {
                    callback(page);
                }
            });
        }
    };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {
        get_sum_case: Class.get_sum_case
    };
    window.base = {
        change_court: function (_param_court_uid) {
            $(r.court_list).each(function (i, n) {
                if (n.uid == _param_court_uid) {
                    console.log(_param_court_uid, n.uid);
                    var uri_arr = window.location.href.split('?')[0];
                    var uri = uri_arr + ('?courtUid=' + _param_court_uid);
                    window.location.href = decodeURI(uri);
                }
            });
        },
        get_court: function (_param_court_uid) {
            var court_basic = null;
            $(r.court_list).each(function (index, elem) {
                if (_param_court_uid == elem.uid) {
                    court_basic = ready.court_list[index];
                }
            });
            return court_basic;
        },
        logout: function () {
            $.get(r.base_path + "oauth/signOut", {}, function () {
                utils.remove_cookie("_username");
                utils.remove_cookie("_court_name");
                utils.remove_cookie("_court_uid");
                utils.remove_cookie("_court_ip");
                utils.remove_cookie("_level");
                utils.remove_cookie("_user_uid");
                localStorage.clear();
                window.location.href = r.base_path + "login.html";
            });
        },
        back: function () {
            history.go(-1);
        },
        pagination: function (elm, options) {
            draw(parseInt(options.currentPage), parseInt(options.totalPages));

            function draw(currentPage, totalPages) {
                var page_el = $('<div class="text-center"> <ul class="cmp-pagination"></ul></div>');
                var previous = $('<li><a class="cmp-previous">&#60上一页</a></li>');
                previous.click(function () {
                    //点击上一页
                    var previous_page = currentPage - 1;
                    if (previous_page > 0) {
                        options.currentPage = previous_page;
                        options.onPageClicked(options.currentPage);
                        base.pagination(elm, options);
                    }
                });
                page_el.find('ul').append(previous);
                for (var i = 4; i > 0; i--) {
                    var chemical_i = currentPage - i;
                    if (chemical_i > 0) {
                        var item_i = $('<li><a>' + chemical_i + '</a></li>');
                        item_i.click(function () {
                            //点击当前页之前的
                            options.currentPage = $(this).find('a').html();
                            options.onPageClicked(options.currentPage);
                            base.pagination(elm, options);
                        });
                        page_el.find('ul').append(item_i);
                    }
                }
                var active = $('<li><a class="active">' + currentPage + '</a></li>');//当前页
                page_el.find('ul').append(active);
                for (var j = 1; j < 5; j++) {
                    var chemical_j = currentPage + j;
                    if (chemical_j <= totalPages) {
                        var item_j = $('<li><a>' + chemical_j + '</a></li>');
                        item_j.click(function () {
                            //点击当前页之后的
                            options.currentPage = $(this).find('a').html();
                            options.onPageClicked(options.currentPage);
                            base.pagination(elm, options);
                        });
                        page_el.find('ul').append(item_j);
                    }
                }
                var next = $('<li><a class="cmp-next">下一页&#62</a></li>');
                next.click(function () {
                    //点击下一页
                    var next_page = currentPage + 1;
                    if (next_page <= totalPages) {
                        options.currentPage = next_page;
                        options.onPageClicked(options.currentPage);
                        base.pagination(elm, options);
                    }
                });
                page_el.find('ul').append(next);
                var go = $('<li class="cmp-go-li">跳至<input >页<a class="cmp-go">GO</a></li>');
                go.find('a').click(function () {
                    var go_input = go.find('input');
                    var go_page = go_input.val();
                    go_input.val('');
                    if (go_page > totalPages) {
                        go_page = totalPages;
                    }
                    if (go_page < 1) {
                        go_page = 1;
                    }
                    options.currentPage = go_page;
                    options.onPageClicked(options.currentPage);
                    base.pagination(elm, options);
                });
                page_el.find('ul').append(go);
                var total_ext = $('<li>共<span>' + totalPages + '</span>页</li>');
                page_el.find('ul').append(total_ext);
                $(elm).html('');
                $(elm).append(page_el);
            }
        }
    };
}(window);
